{extend name="base"/}
{block name="resources"}
<style>
	.ns-form {margin-top: 0;}
</style>
{/block}
{block name="main"}
<div class=" layui-form ns-form">
	<div class="layui-form-item">
		<label class="layui-form-label"><span class="required">*</span>主营行业名称：</label>
		<div class="layui-input-block">
			<input type="text" name="category_name" lay-verify="required" value="{$category_info.data.category_name}" class="layui-input ns-len-long" autocomplete="off">
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label ">排序：</label>
		<div class="layui-input-block">
			<input type="number" name="sort" class="layui-input ns-len-short" lay-verify="sorts" value="{$category_info.data.sort}" autocomplete="off">
		</div>
		<div class="ns-word-aux">
			<p>排序值必须为整数；数值越小，越靠前</p>
		</div>
	</div>

	<div class="layui-form-item">
		<label class="layui-form-label ">保证金金额：</label>
		<div class="layui-input-block">
			<div class="layui-input-inline">
				<input type="number" name="baozheng_money" lay-verify="flo" class="layui-input ns-len-short" value="{$category_info.data.baozheng_money}" autocomplete="off">
			</div>
			<span class="layui-form-mid">元</span>
		</div>
		<div class="ns-word-aux">
			<p>保证金不能小于0，可保留两位小数</p>
		</div>
	</div>

	<div class="ns-form-row">
		<button type="button" class="layui-btn ns-bg-color" lay-submit lay-filter="save">保存</button>
		<button class="layui-btn layui-btn-primary" onclick="back()">返回</button>
	</div>

	<input type="text" name="category_id" lay-verify="required" value="{$category_info.data.category_id}" class="layui-input layui-hide">
</div>
{/block}
{block name="script"}
<script>
	layui.use('form', function() {
		var form = layui.form,
			repeat_flag = false; //防重复
		form.render();

		form.on('submit(save)', function(data) {
			if(repeat_flag) return false;
			repeat_flag = true;

			$.ajax({
				url: ns.url("admin/shopcategory/editCategory"),
				data: data.field,
				dataType: 'JSON',
				type: 'POST',
				success: function(res) {
					repeat_flag = false;
					
					if (res.code == 0) {
						layer.confirm('编辑成功', {
							title:'操作提示',
							btn: ['返回列表', '继续操作'],
							yes: function(){
								location.href = ns.url("admin/shopcategory/lists")
							},
							btn2: function() {
								location.reload();
							}
						});
					}else{
						layer.msg(res.message);
					}
				}
			});
		});
		
		/**
		 * 表单验证
		 */   
		form.verify({
			sorts: function(value){ 
				if (value == '') {
					return;
				}
				if (value%1 != 0) {
					return '排序数值必须为整数';
				}
				if (value < 0) {
					return '排序数值必须为大于0';
				}
			},
			flo: function (value) {
				console.log(1);
				if (value == '') {
					return;
				}
				var reg = /^(0|[1-9]\d*)(\s|$|\.\d{1,2}\b)/;
				if (!reg.test(value)) {
					return '保证金不能小于0，可保留两位小数！'
				}
			}
		});   
	});
	
	function back(){
		location.href = ns.url("admin/shopcategory/lists")
	}
</script>
{/block}